/*
 * 组件注释
 * @Author: machinist_wq
 * @Date: 2022-09-02 23:08:42
 * @LastEditors: machinist_wq
 * @LastEditTime: 2022-11-04 19:34:00
 * @Description: 删除提示框
 * 人生无常！大肠包小肠......
 */
"use strict";
import { Attributes, FC, ReactElement, ReactNode } from "react";
import { Modal, ModalFuncProps } from "antd";
import { ExclamationCircleOutlined } from "@ant-design/icons";
import React from "react";

type ICloneProps = Partial<unknown> & Attributes;
interface IProps {
  title: string;
  disabled?: boolean;
  onConfirm?: () => void;
  children?: ReactNode;
  content?: ReactNode;
  (x: string): keyof ModalFuncProps;
}
const Index: FC<IProps> = (props: IProps): ReactElement => {
  const {
    title = "提示",
    disabled,
    onConfirm = () => { },
    children,
    content,
    ...args
  } = props;

  const confirm = () => {
    Modal.confirm({
      title: title,
      icon: <ExclamationCircleOutlined />,
      content: content,
      okText: "确认",
      cancelText: "取消",
      ...args,
      onOk: () => onConfirm(),
    });
  };

  return (
    <span
      onClick={(e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => {
        e.stopPropagation();
        !disabled ? confirm() : null;
      }}>
      {React.isValidElement(children)
        ? React.cloneElement(children, { disabled } as ICloneProps)
        : children}
    </span>
  );
};
export default Index;
